<template>
  <button
      :class="{'fakeButton':true,round,loading,iconRight:iconPosition==='right',big:size==='big',small:size==='small',warn:color==='warn',danger:color==='danger'}"
      ref="button"
      v-bind="$attrs"
      v-on="$listeners"
      :style="this.color && this.color !== 'warn' && this.color !== 'danger' && this.color !== 'main'?{backgroundColor:color}:''"
  >
    <i v-if="icon" :class="`iconfont icon-${icon}`"></i>
    <slot></slot>
    <i v-if="loading" class="iconfont icon-loading"></i>
  </button>
</template>
<script>

  export default {
    props: {
      loading: {
        type: Boolean,
        default: false
      },
      color: String,
      size: String,
      icon: String,
      round: Boolean,
      iconPosition: {
        type: String,
        default: 'left'
      }
    }
  }
</script>

<style lang="less">
  @import "../../assets/base.less";

  @keyframes loading-rotate {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }

  .fakeButton {
    background: @main-color;
    border-radius: 4px;
    padding: 0 15px;
    height: 30px;
    line-height: 30px;
    color: white;
    font-size: @base-fontSize;
    cursor: pointer;
    display: flex;

    &:hover {
      filter: brightness(1.1);
    }

    &:focus {
      outline: none;
    }

    &:disabled,&:hover{
      filter:none;
    }
    &:disabled{
      cursor: not-allowed;
      background-color: #777;
    }

    i {
      margin-left: 0;
      margin-right: 5px;
    }
  }

  .loading {
    i {
      animation: loading-rotate 2s infinite linear;
      margin-right: 0;
      margin-left: 5px;
    }
  }

  .danger {
    background: @danger-color;
  }

  .warn {
    background: @warn-color;
  }

  .big {
    height: 32px;
    line-height: 32px;
    font-size: 16px;
    padding: 0 20px;

    &.round {
      border-radius: 15px;
    }
  }

  .small {
    height: 25px;
    line-height: 25px;
    font-size: 12px;
    padding: 0 12px;

    &.round {
      border-radius: 12px;
    }
  }

  .round {
    border-radius: 15px;
  }

  .iconRight {
    i {
      order: 1;
      margin-left: 5px;
      margin-right: 0;
    }
  }
</style>